package cn.wk.user.service.impl;

import cn.wk.basic.exception.DiyException;
import cn.wk.basic.service.impl.BaseServiceImpl;
import cn.wk.user.domain.User;
import cn.wk.user.mapper.UserMapper;
import cn.wk.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class UserServiceImpl extends BaseServiceImpl<User> implements IUserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public void checkPhone(String phone) throws DiyException {
        //先判断传进来的phone是否有值
        if(StringUtils.isEmpty(phone)){
            throw new DiyException("手机号没有填写");
        }

        //根据传进来的phone去数据库查询
        User user = userMapper.findByPhone(phone);
        //如果存在该用户就抛出异常
        if(user != null){
            throw new DiyException("手机号已被注册");
        }
    }

    @Override
    public User findByLogininfoId(Long logininfoId) {
        return userMapper.findByLogininfoId(logininfoId);
    }
}
